package com.yx.cloud.activity;

import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;

import com.yx.cloud.R;
import com.yx.cloud.adapter.CountryCodeAdapter;
import com.yx.cloud.base.BaseActivity;
import com.yx.cloud.bean.CountryCodeBean;
import com.yx.cloud.databinding.CountrycodeActivityBinding;
import com.yx.cloud.utils.CountryCodeUtils;
import com.yx.cloud.utils.RomUtils;
import com.iot.common.utils.LogUtils;

import java.util.List;

/**
 * Created by Administrator on 2018/12/30.
 */

public class CountryCodeActivity extends BaseActivity implements View.OnClickListener {
    private static final String TAG = "CountryCodeActivity";

    private List<CountryCodeBean> mList;
    private CountrycodeActivityBinding binding;

    @Override
    public void onCreate() {
       //LanguageUtils.getAndsetLanguage(this);
        binding = CountrycodeActivityBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        initData();
    }

    private void initData() {
        mList = CountryCodeUtils.getCountryCodeList(this);
        binding.lvCountrycode.setAdapter(new CountryCodeAdapter(this, mList));
        binding.lvCountrycode.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String countryName = mList.get(position).getName();
                int countryCode = mList.get(position).getCode();
                String zh = mList.get(position).getZh();
                String en = mList.get(position).getEn();
                Log.d(TAG, countryCode + " : cccccccccccccccccddddddddddddddddd : " + countryName);
                LogUtils.i("en : " + en);
                Intent intent = new Intent();
                intent.putExtra("countryName", countryName);
                intent.putExtra("countryCode", countryCode + "");
                intent.putExtra("zh", zh);
                intent.putExtra("en", en);
                setResult(2, intent);
                //TODO 这个结果2 是啥意思  RESULT_OK =-1
                finish();
            }
        });
        binding.ivCountrycodeReturn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (RomUtils.isFastClick()) {
            return;
        }
        switch (v.getId()) {
            case R.id.iv_countrycode_return:
                finish();
                break;
        }
    }
}
